package com.blank.web.servlet;

import com.blank.web.bean.ClassBean;
import com.blank.web.service.ClassService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "addClassServlet",urlPatterns = "/addClassInfo")
public class addClassServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1、设置字符编码
        request.setCharacterEncoding("utf-8");
        ClassBean classBean = new ClassBean();
        //2、获取请求中的参数并进行相应的设置
        classBean.setGrade( Integer.parseInt(request.getParameter("grade")));
        classBean.setTeacherName(request.getParameter("teacherName"));
        classBean.setSlogan(request.getParameter("slogan"));
         classBean.setClassNum(Integer.parseInt(request.getParameter("classNum")));
        //3、调用service层的ClassService中的方法
        ClassService classService = new ClassService();
        classService.addClass(classBean);
        //4、进行页面的跳转
        request.getRequestDispatcher("showClassInfo").forward(request,response);


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
